<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    const array = [1, 3, 2, 3, 5, 1, 2, 4, 9, 3, 6, 7, 2, 4, 8, 5, 7, 3, 8, 2, 4, 9, 1, 6]
  </script>

  <!-- <script>
    // 1. filter()
    function noRepeat(arr) {
      // return arr.filter(function(item, index, array) {
      //   return arr.indexOf(item) === index
      // })
      return arr.filter((item, index) => arr.indexOf(item) === index)
    }
    console.log('后：', noRepeat(array))
  </script> -->

  <!-- <script>
    // 2. Set
    function noRepeat(arr) {
      // return Array.from(new Set(arr))
      return [...new Set(arr)]
    }
    console.log('后：', noRepeat(array))
  </script> -->

  <!-- <script>
    // 3. 利用空数组，循环遍历原数组，判断是否存在元素
    function noRepeat(arr) {
      var newArray = []
      for (var i = 0, len = arr.length; i < len; i++) {
        if (newArray.indexOf(arr[i]) === -1) {
          newArray.push(arr[i])
        }
      }
      return newArray
    }
    console.log('后：', noRepeat(array))
  </script> -->

  <script>
    // 4. reduce()
    function noRepeat(arr) {
      return arr.reduce((result, current) => {
        if (!result.includes(current)) {
          result.push(current)
        }
        return result
      }, [])
    }
    console.log('后：', noRepeat(array))
  </script>
</body>
</html>